/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.plaf.*;
import com.sun.lwuit.List;
import java.util.Hashtable;
import java.io.*;

/**
 * @author Rudi
 */
public class GUI extends MIDlet implements ActionListener  {
    //forms
    Form home;

    //commands
    Command exitCommand;
    
    //buttons
    Button up;      //up, down, left and right buttons
    Button down;
    Button left;
    Button right;

    //images
    Image image;    //used to store banner image

    //labels
    Label banner;   //used to display banner

    //lists
    List list;      //used as a list for user items

    //text areas
    TextArea big;   //used to store the current plot text

    
    public void startApp() {
        Display.init(this); //initialise display

        setTheme();
        createUI();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void actionPerformed(ActionEvent ae) {  //button press action control
      if (ae.getCommand() == exitCommand){   //exit button pressed
          notifyDestroyed();
      }
      else if(ae.getSource() == up){
          big.setText("up pressed");
      }
      else if(ae.getSource() == down){
          big.setText("down pressed");
      }
      else if(ae.getSource() == left){
          big.setText("left pressed");
      }
      else if(ae.getSource() == right){
          big.setText("right pressed");
      }
    }

    private void createUI()  {  //function to create the GUI and display
        home = new Form("SkiFree"); //create new form
        //home.setLayout(new BorderLayout());

        //create exit button
        exitCommand = new Command("Exit");
        home.addCommand(exitCommand);
        home.setCommandListener(this);

        //add image (top)
        try{
            image = Image.createImage("/GUI/banner.png");
            banner = new Label (image);
            home.addComponent(banner);
        }
        catch (IOException e)
        {
            System.err.println ("Error: Banner file not found" + e);
        }

        //text area
        big = new TextArea("You are entering a dark"
                + "fdjsnajklsdfskdlafds asjkdlfjdsa; sdf sdf"
                + "....\n\n You found an item: Bone",3,40,TextArea.UNEDITABLE);
        big.setFocusPainted(false);
        home.addComponent(big);

        //direction buttons
        up = new Button("UP");
        home.addComponent(up);
        up.addActionListener(this);

        down = new Button("DOWN");
        home.addComponent(down);
        down.addActionListener(this);

        left = new Button("LEFT");
        home.addComponent(left);
        left.addActionListener(this);
        
        right = new Button("RIGHT");
        home.addComponent(right);
        right.addActionListener(this);

        //item list
        TextArea title = new TextArea("Items:\n------",3,40,TextArea.UNEDITABLE);
        title.setFocusable(false);
        list = new List();
        list.addItem("Items:");
        list.addItem("Key");
        list.addItem("Bone");
        list.addItem("Knife");
        list.setFocusable(false);

        home.addComponent(list);

        //example for deleting item:
        com.sun.lwuit.list.ListModel mdl = list.getModel();
        mdl.removeItem(2);
        list.setModel(mdl);




        home.show();
    }

    public void setTheme()
    {
        UIManager uim = UIManager.getInstance();
        Hashtable ht = new Hashtable();
        ht.put("sel#" + Style.BG_COLOR, "660099");
        ht.put(Style.BG_COLOR, "333366");
        ht.put(Style.FG_COLOR, "cccccc");
        uim.setThemeProps(ht);
    }
    

}
